package com.yiwenup.leetcode.site;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.site
 * @Author yiwenup
 * @Date 2024-12-23 21:53:00
 * @Description https://leetcode.cn/problems/implement-stack-using-queues/description/
 */
public class No0225 {
    private final Deque<Integer> queue;

    public No0225() {
        queue = new ArrayDeque<>();
    }

    public void push(int x) {
        queue.offerLast(x);
        int c = queue.size();
        while (c > 1) {
            queue.offerLast(queue.pollFirst());
            c--;
        }
    }

    public int pop() {
        return queue.pollFirst();
    }

    public int top() {
        return queue.peekFirst();
    }

    public boolean empty() {
        return queue.isEmpty();
    }
}
